package com.bjsxt.orders.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bjsxt.common.util.PageInfoUtil;
import com.bjsxt.orders.dao.IAOrderPayDao;
import com.bjsxt.orders.pojo.AOrderPay;
import com.bjsxt.orders.service.IOrderPayService;

@Service("orderPayService")
public class OrderPayServiceImpl implements IOrderPayService
{
	@Resource
	private IAOrderPayDao orderPayDao;
	
	@Override		  
	public JSONObject insertOrderPayService(AOrderPay orderPay)
	{
		JSONObject resultJson = new JSONObject();

		int insert = this.orderPayDao.insert(orderPay);

		if (insert > 0)
		{
			resultJson.put("code", "1");
			resultJson.put("info", "账单添加成功");
			JSONObject data = new JSONObject();
			data.put("id", orderPay.getId());
			resultJson.put("data", data);
		} else
		{
			resultJson.put("code", "0");
			resultJson.put("info", "账单添加失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteOrderPayService(Map<String, Object> condMap)
	{
		JSONObject resultJson = new JSONObject();
		int delete = this.orderPayDao.delete(condMap);
		if (delete > 0)
		{
			resultJson.put("code", "1");
			resultJson.put("info", "账单删除成功");
			JSONObject data = new JSONObject();
			data.put("删除个数", delete);
			resultJson.put("data", data);
		} else
		{
			resultJson.put("code", "0");
			resultJson.put("info", "账单删除失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject updateOrderPayService(AOrderPay orderPay)
	{
		JSONObject resultJson = new JSONObject();
		int update = this.orderPayDao.update(orderPay);

		if (update > 0)
		{
			resultJson.put("code", "1");
			resultJson.put("info", "账单修改成功");
			JSONObject data = new JSONObject();
			data.put("id", orderPay.getId());
			resultJson.put("data", data);
		} else
		{
			resultJson.put("code", "0");
			resultJson.put("info", "账单修改失败");
		}
		return resultJson;
	}

	@Override
	public AOrderPay findOneOrderPayService(Map<String, Object> condMap)
	{

		return this.orderPayDao.findOne(condMap);
	}

	@Override
	public List<AOrderPay> findListOrderPayService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		
		if (pageInfoUtil == null)
		{
			/* 不分页查询 */
			return this.orderPayDao.findList(condMap);
		} else
		{
			/* 分页查询 */
			/* 先查总记录数 */
			condMap.put("pageOperation", "true");
			List<AOrderPay> findList = this.orderPayDao.findList(condMap);
			pageInfoUtil.setTotalRecord(findList.get(0).getId());
			/* 查询总记录数 */
			condMap.put("pageOperation", "false");
			condMap.put("currRecord", pageInfoUtil.getCurrRecord());
			condMap.put("pageSize", pageInfoUtil.getPageSize());
			List<AOrderPay> list = this.orderPayDao.findList(condMap);
			return list;
		}
	}
	/* =================账单的service的实现结束==================== */
}
